package com.zw.cloud.mybatis.plus.event;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONWriter;
import com.google.common.eventbus.AllowConcurrentEvents;
import com.google.common.eventbus.AsyncEventBus;
import com.google.common.eventbus.EventBus;
import com.google.common.eventbus.Subscribe;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;

@Component
@Slf4j
public class EventConsumer {
    @Resource
    private AsyncEventBus asyncEventBus;
    @Resource
    private EventBus syncEventBus;

    @PostConstruct
    public void init() {
        asyncEventBus.register(this);
        syncEventBus.register(this);
    }

    @Subscribe
    public void handlerEvent(BaseEvent event) {
        log.info("[EventConsumer][handlerEvent]message is {},thread is {}", JSON.toJSONString(event, JSONWriter.Feature.WriteMapNullValue),Thread.currentThread().getName());
    }

}
